home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
PsL Monthly 1993 December
/
PSL Monthly Shareware CD-ROM (December 1993).iso
/
prgmming
/
dos
/
basic
/
password.txt
< prev
next >
Wrap
Text File
|
1992-10-14
|
3KB
|
74 lines
October 10, 1992
by Raymond W. Six
CompuServe: 70530,433
Here's a way to create a 'Password' style text box completely with
VB/DOS code - no custom controls. Any questions, comments, and/or
suggestions welcomed.
Do This:
1) Create a normal TEXT BOX control to use for the password box.
{let's name it Password_Text for this example}
2) Create a LABEL control and name it PasswordDisplay_Label.
3) Enlarge the form and move Password_Text over past what was the
edge of the form, then change to form size back so that the
Password_Text control is no longer visible. DO NOT CHANGE THE
VISIBLE OR ENABLED PROPERTIES OF Password_Text.
4) Set the BorderStyle of PasswordDisplay_Label to Fixed-Single.
5) Position and size PasswordDisplay_Label however you would like
the password box to appear to the user.
6) Add this code to Password_Text's 'Change' event:
SUB Password_Text_Change()
PasswordDisplay_Label.Caption = STRING$(LEN(Password_Text.Text),"*")
END SUB
7) Add this code to Password_Text's 'GotFocus' event:
SUB Password_Text_GotFocus()
PasswordDisplay_Label.BorderStyle = 2
END SUB
8) Add this code to Password_Text's 'LostFocus' event:
SUB Password_Text_LostFocus()
PasswordDisplay_Label.BorderStyle = 1
END SUB
9) Add this code to PasswordDisplay_Label's 'Click' event:
SUB PasswordDisplay_Label_Click()
Password_Text.SETFOCUS
END SUB
Here's the way it works:
Even though the actual Password_Text TEXT BOX is not visible on the screen,
users may still tab into it (i.e. it may still get the 'Focus'). Also,
keystrokes may still be entered into this control - which cause a 'Change'
event - which (via the code we put in) will update the 'fake' password box
(PasswordDisplay_Label) to look like a 'Password' style text box.
One problem that occurs is that no 'Caret' (typing cursor) will appear in
the 'fake' password box. This makes it difficult for the user to tell
which control has the focus. That's where the GetFocus and LostFocus code
comes in.
When Password_Text gets the 'Focus', the BorderStyle of the fake password
box (PasswordDisplay_Label) will be changed to Fixed-Double. The reverse
will occur when 'Focus' shifts AWAY from Password_Text.
In case the user decides to use the mouse to change focus to the password
box, the code placed in the 'fake' password box will re-direct focus to
Password_Text instead.
October 10, 1992
by Raymond W. Six
CompuServe: 70530,433